package view;

import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JCheckBox;
import model.*;
import javax.swing.*;

public class frmLectura extends JFrame {
	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JButton btnAceptar = null;
	private JButton btnCancelar = null;
	private JLabel lblTitulo = null;
	private JLabel lblAutor = null;
	private JTextField txtTitulo = null;
	private JTextField txtAutor = null;
	private Fachada jebi= null;

	/**
	 * This is the default constructor
	 */
	public frmLectura() {
		super();
		initialize();
		this.btnCancelar.addActionListener(new java.awt.event.ActionListener(){
			public void actionPerformed(java.awt.event.ActionEvent evt) {
	              btnCancelarActionPerformed(evt);
	            }
		});
		this.btnAceptar.addActionListener(new java.awt.event.ActionListener(){
			public void actionPerformed(java.awt.event.ActionEvent evt) {
	              btnAceptarActionPerformed(evt);
	            }
		});
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(376, 146);
		this.setContentPane(getJContentPane());
		this.setTitle("Alta de Lecturas");
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			lblAutor = new JLabel();
			lblAutor.setBounds(new Rectangle(32, 46, 59, 16));
			lblAutor.setText("Autor");
			lblTitulo = new JLabel();
			lblTitulo.setBounds(new Rectangle(31, 15, 60, 18));
			lblTitulo.setText("Titulo");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getBtnAceptar(), null);
			jContentPane.add(getBtnCancelar(), null);
			jContentPane.add(lblTitulo, null);
			jContentPane.add(lblAutor, null);
			jContentPane.add(getTxtTitulo(), null);
			jContentPane.add(getTxtAutor(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes btnAceptar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnAceptar() {
		if (btnAceptar == null) {
			btnAceptar = new JButton();
			btnAceptar.setBounds(new Rectangle(47, 75, 102, 24));
			btnAceptar.setText("Acepar");
		}
		return btnAceptar;
	}

	/**
	 * This method initializes btnCancelar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnCancelar() {
		if (btnCancelar == null) {
			btnCancelar = new JButton();
			btnCancelar.setBounds(new Rectangle(211, 75, 103, 24));
			btnCancelar.setText("Salir");
		}
		return btnCancelar;
	}

	/**
	 * This method initializes txtTitulo	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTxtTitulo() {
		if (txtTitulo == null) {
			txtTitulo = new JTextField();
			txtTitulo.setBounds(new Rectangle(105, 16, 243, 18));
		}
		return txtTitulo;
	}

	/**
	 * This method initializes txtAutor	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTxtAutor() {
		if (txtAutor == null) {
			txtAutor = new JTextField();
			txtAutor.setBounds(new Rectangle(106, 46, 240, 17));
		}
		return txtAutor;
	}
	private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt){
		this.dispose();
	}
	
	private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt){
		this.ComportamientobtnAceptar();
	}
	
	private void ComportamientobtnAceptar(){
		if (this.jebi.AltaFicha(this.lblAutor.getText(),this.lblTitulo.getText())){
			this.jebi.altaFichaPersistente(this.jebi.getFicha());
			disparoMensaje("Ficha Ingresada con exito");
			frmModLectura modlec = new frmModLectura(this.jebi);
			modlec.setVisible(true);
			this.dispose();
			// cerrar ventana y llamar a frmModLectura
		}
		else
			disparoMensaje("El sistema no pudo ingresar la lectura revise los datos ingresados");
		
	}
	
	private void disparoMensaje(String str){
		JOptionPane.showMessageDialog(null, str, "Mensaje del Sistema", JOptionPane.INFORMATION_MESSAGE);
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"
